﻿using System.Collections;
using UnityEngine;

public class FramingProcessing
{
    // save the last frame time.
    private float _lastTime;
    // the time of per frame
    private readonly float _maxTime;

    public FramingProcessing(int frameCount)
    {
        _maxTime = 1.0f / frameCount;
        Start();
    }

    private void Start()
    {
        _lastTime = Time.realtimeSinceStartup;
    }

    public IEnumerator UpdateFrame()
    {
        var curTime = Time.realtimeSinceStartup;
        if (curTime - _lastTime >= _maxTime)
        {
            _lastTime = curTime;
            yield return null;
        }
    }
}